package de.java.swing.extension.ui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JLabel;

import de.java.swing.extension.utils.MenubarConstants;

/**
 * TODO Kommentar.
 * 
 * @author Patrick Haas
 * @since 1.0.0
 * 
 */
public class MenuItem extends ExtendedPanel implements MenubarConstants {

	private static final long serialVersionUID = -5479732499556990072L;

	private Color mouseOutColor = DEFAULT_MOUSE_OUT_COLOR;

	private Color mouseOverColor = DEFAULT_MOUSE_OVER_COLOR;

	private ExtendedPanel westPane;

	private ExtendedPanel eastPane;

	private ExtendedPanel centerPane;

	private JLabel textLabel;

	private Menu parent;

	private MenuItem() {
		initialize();
	}

	/**
	 * @return the westPane
	 */
	public ExtendedPanel getWestPane() {
		return westPane;
	}

	/**
	 * @return the eastPane
	 */
	public ExtendedPanel getEastPane() {
		return eastPane;
	}

	/**
	 * @return the centerPane
	 */
	public ExtendedPanel getCenterPane() {
		return centerPane;
	}

	public MenuItem(String title) {
		this();
		this.textLabel.setText(title);
	}

	public void setMouseOverColor(Color c) {
		mouseOverColor = c;
	}

	public Color getMouseOverColor() {
		return mouseOverColor;
	}

	public void setMouseOutColor(Color c) {
		mouseOutColor = c;
		this.textLabel.setForeground(c);
	}

	public Color getMouseOutColor() {
		return mouseOutColor;
	}

	public void setTitle(String title) {
		this.textLabel.setText(title);
	}

	private void initialize() {
		this.setLayout(new BorderLayout());
		this.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseEntered(MouseEvent e) {
				textLabel.setForeground(mouseOverColor);
			}

			@Override
			public void mouseExited(MouseEvent e) {
				textLabel.setForeground(mouseOutColor);
			}
		});

		westPane = new ExtendedPanel(1.0f);
		westPane.setPreferredSize(new Dimension(4, 0));
		this.add(BorderLayout.WEST, westPane);

		centerPane = new ExtendedPanel(1.0f);
		centerPane.setLayout(new BorderLayout());
		this.add(BorderLayout.CENTER, centerPane);

		eastPane = new ExtendedPanel(1.0f);
		eastPane.setPreferredSize(new Dimension(4, 0));
		this.add(BorderLayout.EAST, eastPane);

		textLabel = new JLabel();
		textLabel.setForeground(mouseOutColor);
		centerPane.add(textLabel);
	}

	/**
	 * @return the parent
	 */
	public Menu getMenu() {
		return parent;
	}

	/**
	 * @param parent
	 *            the parent to set
	 */
	public void setMenu(Menu parent) {
		this.parent = parent;
	}
}
